/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
#ifndef PLELF_RELOCATION32_H
#define PLELF_RELOCATION32_H

#include <elf/plelfstddef.h>

namespace PLSDK {

#define PLELF32_R_SYM(i)	((i) >> 8)
#define PLELF32_R_TYPE(i)   ((unsigned char)(i))
#define PLELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))

/**
 * Elf relocation entry.
 */
class PLELFRelocation32 {
public:
	/**
	 * Constructor.
	 */
	PLELFRelocation32() {}
    /**
     * Get the symbol information.
     *
     * @return The symbol information.
     */
    inline Elf32_Word infoSymbol();
    /**
     * Get the type.
     *
     * @return The type.
     */
    inline Elf32_Word infoType();
	/**
	 * This member gives the location at which to apply the relocation action.
	 * For a relocatable file, the value is the byte offset from the beginning
	 * of the section to the storage unit affected by the relocation. For an
	 * executable file or a shared object, the value is the virtual address of
	 * the storage unit affected by the relocation.
	 */
	Elf32_Addr r_offset;
	/**
	 * This member gives both the symbol table index with respect to which the
	 * relocation must be made, and the type of relocation to apply. For example,
	 * a call instruction's relocation entry would hold the symbol table index of
	 * the function being called. If the index is STN_UNDEF, the undefined symbol
	 * index, the relocation uses 0 as the ``symbol value''. Relocation types are
	 * processor-specific; descriptions of their behavior appear in the processor
	 * supplement.
	 */
	Elf32_Word r_info;
} __attribute__((packed));

Elf32_Word PLELFRelocation32::infoSymbol() {
    return PLELF32_R_SYM(r_info);
}

Elf32_Word PLELFRelocation32::infoType() {
    return PLELF32_R_TYPE(r_info);
}

}

#endif
